import { createRouter, createWebHashHistory } from 'vue-router'
import store from '@/store'

export const routes = [
  {
    path: '/',
    name: 'login',
    component: () => import('../views/LoginView.vue'),
  },
  {
    path: '/home',
    name: 'home',
    label: "首页",
    component: () => import('../views/HomeView.vue'),
    children: [
      {
        path: '/permissions',
        name: 'permissions',
        label: "权限管理", 
        component: () => import('../views/permissions/index.vue'),

        children: [

          {
            path: 'adminlist',
            name: 'adminlist',
            label: "角色列表",
            component: () => import('../views/permissions/adminlist.vue'),

          },
          {
            path: 'powerlist',
            name: 'powerlist',
            label: "权限列表",
            component: () => import('../views/permissions/powerlist.vue'),

          },

        ]
      },
      {
        path: '/goods',
        name: 'goods',
        label: "商品管理",    
        component: () => import('../views/goods/index.vue'),
        children: [
          {
            path: 'list',
            name: 'list',
            label: "商品列表",
            component: () => import('../views/goods/list.vue'),

          },
          {
            path: 'params',
            name: 'params',
            label: "商品查询",
            component: () => import('../views/goods/params.vue'),

          },
          {
            path: 'categories',
            name: 'categories',
            label: "商品分类",
            component: () => import('../views/goods/categories.vue'),

          },
        ]
      },
      {
        path: '/orders',
        name: 'orders',
        label: "订单管理",
        component: () => import('../views/orders/index.vue'),
        children: [
          {
            path: 'index',
            name: 'index',
            label: "订单管理",
            component: () => import('../views/orders/index.vue')
          },
          {
            path: 'prolist',
            name: 'prolist',
            label: "订单列表",
            component: () => import('../views/orders/ProList.vue')
          },
        ]
      },
      {
        path: '/beauty',
        name: 'beauty',
        label:"页面美化",
        component: () => import('../views/beauty/index.vue')
      },
      {
        path: '/user',
        name: 'user',
        label: "用户管理", 
        component: () => import('../views/user/index.vue')
      },
      {
        path: '/home',
        name: 'home',
        label: "首页", 
        component: () => import('../views/home/index.vue')
      }
    ]
  },


]
export const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes

})
//配置路由全局前置守卫导航
router.beforeEach((to, from) => {
  if (to.name !== 'login') {
    if (!window.localStorage.getItem('token')) {
      //跳转到登录页
      return '/'
    }
  }
})

export default router
